﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMyExaminTopicList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MyExaminTopicOutParam result = new MyExaminTopicOutParam();
            MyExaminTopicInParam param = new MyExaminTopicInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MyExaminTopicInParam;
                if (string.IsNullOrEmpty(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户ID不能为空";

                    isFlag = false;
                }


                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if (isFlag)
                {
                    //用户是否存在
                    isFlag = InterfaceHelper.CheckLoginIDCountEx(param.user_id);

                    if (!isFlag)
                    {
                        result.code = "0";
                        result.desc = "该用户不存在";
                    }
                }  

                //用户是否能考试
                if (isFlag)
                {
                    isFlag = InterfaceHelper.IsAbleExamination(param.user_id);

                    if (!isFlag)
                    {
                        result.code = "0";
                        result.desc = "您今天答的试题已有两份全对，请明天在来！";
                    } 
                }

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetExamin(param.user_id);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    { 
                        MyExaminTopic itemTemp;
                        TopicOption optionTemp;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new MyExaminTopic();
                            itemTemp.content = dr["TopicContent"].ToString();
                            itemTemp.exam_id = dr["TopicID"].ToString();
                            itemTemp.number = dr["OrderNo"].ToString();

                            DataSet dsOption = InterfaceHelper.GetOption(itemTemp.exam_id);
                            if (dsOption != null && dsOption.Tables[0].Rows.Count > 0)
                            {
                                foreach(DataRow dr2 in dsOption.Tables[0].Rows)
                                {
                                    optionTemp = new TopicOption();
                                    optionTemp.option_content = dr2["optioncontent"].ToString();
                                    optionTemp.option_id = dr2["optionid"].ToString();
                                    itemTemp.options.Add(optionTemp);
                                }
                            }

                            result.data.list.Add(itemTemp);
                        }
                    }  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMyExaminTopicList", SerializeHelper.JsonSerializer<MyExaminTopicInParam>(param), SerializeHelper.JsonSerializer<MyExaminTopicOutParam>(result)); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MyExaminTopicInParam, MyExaminTopicOutParam>();
            else
                SafeProcessRequest<MyExaminTopicInParam, MyExaminTopicOutParam>();
        }
    }

    #region 请求参数
    public class MyExaminTopicInParam
    {
        /// <summary>
        /// 必填， 	用户ＩＤ
        /// </summary>
        public string user_id
        { get; set; }  
    }
    #endregion

    #region 结果参数
    public class MyExaminTopicOutParam
    {
        public MyExaminTopicOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MyExaminTopicList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 考题列表
        /// </summary>
        public MyExaminTopicList data
        { get; set; }
    }

    
    #endregion 
}